package com.xmlt.ui.builder.generator;

import com.xmlt.core.template.instance.AbstractInstance;
import com.xmlt.core.template.instance.MultiInstance;
import com.xmlt.core.template.instance.Value;
import com.xmlt.core.template.tags.AbstractSectionElementVisitor;
import com.xmlt.core.template.tags.TextTag;

public class SectionElementVisitor extends AbstractSectionElementVisitor {
	private StringBuffer stringBuffer;

	protected SectionElementVisitor(AbstractInstance inst) {
		super(inst);
		stringBuffer = new StringBuffer();
	}

	public String getString() {
		return stringBuffer.toString();
	}

	public void handleValue(Value value) {
		String contentValue = String.valueOf(value.getValue());
		stringBuffer.append(contentValue);
	}

	public void handleMultiInstanceStart(MultiInstance multiInstance) {
	}

	public void handleMultiInstanceEnd(MultiInstance multiInstance) {
	}

	public void handleMultiInstanceItemStart(AbstractInstance itemInstance,
			MultiInstance multiInstance, int index) {
	}

	public void handleMultiInstanceItemEnd(AbstractInstance itemInstance,
			MultiInstance multiInstance, int index) {
	}

	@Override
	public void handleTextTag(TextTag textTag) {
		stringBuffer.append(textTag.getText());
	}

	@Override
	public void handleObject(Object o) {
		stringBuffer.append(o);
	}

	@Override
	public void handleException(Exception e) {
		throw new RuntimeException(e);
	}

}
